<template>
  <div class="app-container">
    <el-form :inline="true" :model="searchMap.data" class="demo-form-inline">
      <el-form-item>
        <el-input
          v-model="searchMap.data.copyTitle"
          placeholder="文案标题"
        ></el-input>
      </el-form-item>
      <el-form-item>
       <el-select v-model="searchMap.data.typeId" filterable placeholder="请选择">
            <el-option
            v-for="item in options"
            :key="item.typeId"
            :label="item.label"
            :value="item.typeId">
            </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="search()">搜索</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="success" @click="delChoose()"
          >批量删除</el-button>
      </el-form-item>
      </el-form>
      <el-table ref="multipleTable" :data="copyList" style="width: 100%" @selection-change="handleSelectionChange">
      <el-table-column   type="selection" width="80">
      </el-table-column>
      <el-table-column  v-model="entity.copyTitle" prop="copyTitle" label="文案标题" width="180">
      </el-table-column>
      <el-table-column  v-model="entity.wxbGoods.goodsName" prop="wxbGoods.goodsName" label="商品名称" width="180">
      </el-table-column>
      <el-table-column  v-model="entity.wxbCustomer.customerName" prop="wxbCustomer.customerName" label="商户名称" width="180">
      </el-table-column>
      <el-table-column prop="typeId" label="文案类型">
        <template slot-scope="scope">
          <p v-if="scope.row.typeId == 3">微信文案</p>
          <p v-if="scope.row.typeId == 1">站内文案</p>
          <p v-if="scope.row.typeId == 2">日志文案</p>
        </template>
      </el-table-column>
      <el-table-column  label="文案图片" width="180">
          <template slot-scope="scope">
              <div><img :src="scope.row.imgUrls" /></div>
          </template>
      </el-table-column>
      <el-table-column prop="" label="操作" width="180">
        <template slot-scope="scope">
          <div>
            <el-button
              type="primary"
              icon="el-icon-edit"
              @click="delObject(scope.$index, scope.row)"
              >删除</el-button
              >
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="searchMap.page"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="5"
      layout="total, sizes, prev, pager, next, jumper"
      :total="this.total"
    >
    </el-pagination>

  </div>
</template>
<script>
import { search, delSelect, delOne} from "@/api/copy";
import template from './template.vue';
export default {
  components: { template },
  data() {
    return {
        options: [{
          typeId: 3,
          label: '微信文案'
        }, {
          typeId: 1,
          label: '站内文案'
        }, {
          typeId: 2,
          label: '日志文案'
        }],
      dialogFormVisible_edit: false, //编辑弹窗开关
      dialogFormVisible_add: false, //添加弹窗开关
      visible: false, //删除弹窗开关
      copyList: [],
      selectionList:[],
      entity:{
         wxbGoods:{},
         wxbCustomer:{}
      },
      total: 0,
      searchMap: {
        page: 1,
        limit: 5,
        data: {},
      },
      delData: {}, 
      editDialogData: {}, 
      gooodSpec: {}, 
    };
  },
  methods: {

      uploadSuccess(response, file, fileList) {
      this.entity.imgUrls = response.data;
    },
      delObject(index,row){
          delOne(row).then(res=>{
              console.log(res);
          })
          this.search();
      },

    handleSelectionChange(selection){
		    this.selectionList = []
		    selection.forEach(element => {
		        this.selectionList.push(element)
		    });
		},
    delChoose(){
    var that = this;
    console.log(that.selectionList);
    this.delData = that.selectionList;
    delSelect(this.delData).then((res)=>{
      if (res.success) {
          that.search();
          this.$message({
            showClose: true,
            message: res.msg,
            type: "success",
          });
        } else {
          this.$message({
            showClose: true,
            message: res.msg,
            type: "error",
          });
        }
        console.log(res);
    });
    },
   
    //搜索
    search() {
      var _this = this;
      console.log(this.searchMap);
      search(this.searchMap).then((res) => {
          //console.log(res.data);
          _this.copyList=res.data;
        //_this.entity = res.data;
        _this.total = res.total;
      });
    },
    //保存
    
    handleDelete(index, row) {
      this.delData = row;
      del(this.delData).then((res) => {
        if (res.success) {
          this.search();
          this.$message({
            showClose: true,
            message: res.msg,
            type: "success",
          });
        } else {
          this.$message({
            showClose: true,
            message: res.msg,
            type: "error",
          });
        }
      });
    },
    handleSizeChange(size) {
      this.searchMap.limit = size;
      this.search();
    },
    handleCurrentChange(currentPage) {
      this.searchMap.page = currentPage;
      this.search();
    },
  },
  created() {
    let that = this;
    that.search();
  },
};
</script>